#include "ConditionImpl.h"
#include <assert.h>

AndConditionImpl::AndConditionImpl(Condition* _first,
								   Condition* _second)
{
	assert(_first && _second);

	firstCondition = _first->Copy();
	secondCondition = _second->Copy();
}

AndConditionImpl::AndConditionImpl(const AndConditionImpl& aAndCondition)
	:firstCondition(aAndCondition.firstCondition->Copy()) ,
	 secondCondition(aAndCondition.secondCondition->Copy())
{

}

Condition* AndConditionImpl::Copy()const
{
	return new AndConditionImpl(firstCondition, secondCondition);
}

AndConditionImpl& AndConditionImpl::operator = (const AndConditionImpl& aAndCondition)
{
	if(this == &aAndCondition)
		return *this;

	setFirstCondition(aAndCondition.firstCondition);
	setSecondCondition(aAndCondition.secondCondition);
	return *this;
}

AndConditionImpl::~AndConditionImpl()
{
	if(firstCondition)
		delete firstCondition;
	if(secondCondition)
		delete secondCondition;
}

Condition::ConditionType AndConditionImpl::getConditionType()const
{
	return Condition::SAC_AND_CONDITION;
}

const string* AndConditionImpl::toString()const
{
	string* result = NULL;
	try
	{
		result = new string;
		result->append(*firstCondition->toString());
		result->append(*secondCondition->toString());
	}catch(std::exception& e)
	{
		if(result)
			delete result;
		return NULL;
	}
	return result;
}

const Condition& AndConditionImpl::getFirstCondition()const
{
	return *firstCondition;
}

const Condition& AndConditionImpl::getSecondCondition()const
{
	return *secondCondition;
}
